//package com.authorization.authorizationserveronsso.security.filter;
//
//
//import com.authorization.authorizationserveronsso.security.LoginUser;
//import com.authorization.authorizationserveronsso.security.service.TokenService;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
//import org.springframework.security.core.context.SecurityContextHolder;
//import org.springframework.security.web.authentication.WebAuthenticationDetailsSource;
//import org.springframework.web.filter.OncePerRequestFilter;
//
//import javax.servlet.FilterChain;
//import javax.servlet.ServletException;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
//
///**
// * @author ：hyq
// * @date ：Created in 2021/4/14 14:17
// * @description：
// * @modified By：
// */
////@Component
//public class JwtAuthenticationTokenFilter extends OncePerRequestFilter
//{
//    @Autowired
//    private TokenService tokenService;
//
//    @Override
//    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
//            throws ServletException, IOException {
//        //解析token 获取当前的登录用户信息
//        LoginUser loginUser = tokenService.getLoginUser(request);
//        if ( loginUser != null)
//        {
//            //验证token 实际上是刷新token  避免每次请求都去刷新缓存的过期时间，所以过期时间不足 20 分钟，才会去刷新
//            tokenService.verifyToken(loginUser);
//            //创建对象设置到 SecurityContextHolder 中。 因为，我们已经通过 Token 来完成认证了。
//            UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(loginUser, null, loginUser.getAuthorities());
//            authenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
//            SecurityContextHolder.getContext().setAuthentication(authenticationToken);
//        }
//        chain.doFilter(request, response);
//    }
//}
